#pragma once
#include <pthread.h>

class HungryMode
{
public:
    static HungryMode& GetInstance()
    {
        return _ins;
    }

private:
    HungryMode()
    {}

    ~HungryMode()
    {}

    HungryMode(const HungryMode&) = delete;
    HungryMode& operator=(const HungryMode&) = delete;

private:
    static HungryMode _ins;
};
HungryMode HungryMode::_ins;


class LazyMode
{
public:
    static LazyMode* GetInstance()
    {
        if(_ins == nullptr)
        {
            pthread_mutex_lock(&_mtx);
            if(_ins == nullptr)
                _ins = new LazyMode;
            pthread_mutex_unlock(&_mtx);
        }
        
        return _ins;
    }

private:
    LazyMode()
    {
        pthread_mutex_init(&_mtx, nullptr);
    }

    ~LazyMode()
    {
        pthread_mutex_destroy(&_mtx);
    }

    LazyMode(const LazyMode&) = delete;
    LazyMode& operator=(const LazyMode&) = delete;

private:
    static LazyMode* _ins;
    static pthread_mutex_t _mtx;
};
LazyMode* LazyMode::_ins = nullptr;
pthread_mutex_t LazyMode::_mtx;